﻿@using WsdShop.Model.Enum;
@{
    Layout = null;
}

<style>
    .my-drop-zone {
        border: dotted 3px lightgray;
    }

    .nv-file-over {
        border: dotted 3px red;
    }
    /* Default class applied to drop zones on over */
    .another-file-over-class {
        border: dotted 3px green;
    }

    html, body {
        height: 100%;
    }

    canvas {
        background-color: #f3f3f3;
        -webkit-box-shadow: 3px 3px 3px 0 #e3e3e3;
        -moz-box-shadow: 3px 3px 3px 0 #e3e3e3;
        box-shadow: 3px 3px 3px 0 #e3e3e3;
        border: 1px solid #c3c3c3;
        height: 100px;
        margin: 6px 0 0 6px;
    }

    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 55% !important;
    }

    .form-horizontal .form-group {
        margin-left: 0;
        margin-right: 0;
    }

    .note-image-input {
        margin-bottom: 15px;
    }
</style>
<div ng-controller="OrderInfoController">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START 基本信息panel-->
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>基本信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td>订单 ID:</td>
                                        <td>订单号:</td>
                                        <td>会员:</td>
                                        <td>订单类型</td>
                                        <td>应付:</td>
                                        <td>订单 状态:</td>
                                        <td>下单时间:</td>
                                        <td>支付时间:</td>
                                        <td>支付方式:</td>
                                        <td>用户留言:</td>
                                    </tr>
                                    <tr>
                                        <td>{{Order.Id}}</td>
                                        <td>{{Order.OrderNo}}</td>
                                        <td>{{Order.MemberName}}</td>
                                        <td>{{Order.OrderTypeDes}}</td>
                                        <td>{{Order.OrderType==1?Order.UsePoints:Order.PayMoney}}</td>
                                        <td id="order-status">{{Order.OrderStatusDes}} / {{Order.PayStatusDes}} / {{Order.SendStatusDes}}</td>
                                        <td>{{Order.AddTime}}</td>
                                        <td>{{Order.PayTime}} </td>
                                        <td>
                                            {{Order.PayTypeDes}}
                                        </td>
                                        <td>
                                            {{Order.Remark}}
                                        </td>
                                    </tr>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 收货信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>收货信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td>收货人:</td>
                                        <td>联系方式:</td>
                                        <td>地址:</td>
                                        <td>配送方式:</td>
                                    </tr>
                                    <tr>
                                        <td>{{Order.ReceiveName}}</td>
                                        <td>{{Order.ReceivePhone}}</td>
                                        <td>{{Order.Province}},{{Order.City}},{{Order.Area}},{{Order.ReceiveAddress}}</td>
                                        <td>
                                            申通物流
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--商品信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}" ng-show="Order.OrderType!=@((int)OrderType.积分订单)">
                        <div class="panel-body" >
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>商品信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-left">商品</td>
                                        <td class="text-left">规格</td>
                                        <td class="text-right">数量</td>
                                        <td class="text-right">单品价格</td>
                                        <td class="text-right">会员折扣价</td>
                                        <td class="text-right">单品小计</td>
                                        <td class="text-right">退换货</td>
                                    </tr>
                                    <tr ng-repeat="item in OrderDetail">
                                        <td class="text-left">
                                            {{item.ProductName}}
                                        </td>
                                        <td class="text-left">{{item.SpecName}}</td>
                                        <td class="text-right">{{item.ProductCount}}</td>
                                        <td class="text-right">{{item.ProductPrice}}</td>
                                        <td class="text-right">{{item.DiscountPrice}}</td>
                                        <td class="text-right">{{item.DiscountPrice*item.ProductCount}}</td>
                                        <td class="text-right">{{item.ReturnStatusDes}}</td>
                                    </tr>
                                    
                                    <tr>
                                        <td colspan="4" class="text-right">小计:</td>
                                        <td class="text-right">{{Order.ProductPrice}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}" ng-show="Order.OrderType==@((int)OrderType.积分订单)">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>商品信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-left">商品</td>
                                        <td class="text-right">数量</td>
                                        <td class="text-right">所需积分</td>
                                        <td class="text-right">发货状态</td>
                                    </tr>
                                    <tr ng-repeat="item in OrderDetail">
                                        <td class="text-left">
                                            {{item.ProductName}}
                                        </td>
                                        <td class="text-right">{{item.ProductCount}}</td>
                                        <td class="text-right">{{item.Points}}</td>
                                        <td class="text-right">{{item.SendStatusDes}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--费用信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}" ng-show="Order.OrderType!=@((int)OrderType.积分订单)">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>费用信息@*<a class="btn btn-primary btn-xs" data-original-title="修改费用" title="" data-toggle="tooltip"><i class="fa fa-pencil"></i></a>*@</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-right">小计:</td>
                                        <td class="text-right">运费:</td>
                                        <td class="text-right">积分 (-0):</td>
                                        <td class="text-right">余额抵扣</td>
                                        <td class="text-right">优惠券抵扣</td>
                                        <td class="text-right">价格调整:</td>
                                        <td class="text-right">应付:</td>
                                    </tr>
                                    <tr>
                                        <td class="text-right">{{Order.ProductPrice}}</td>
                                        <td class="text-right">+{{Order.PostageMoney}}</td>
                                        <td class="text-right">-{{Order.PointsPayMoney}}</td>
                                        <td class="text-right">-{{Order.MemberMoney}}</td>
                                        <td class="text-right">-{{Order.ActivityCouponMoney}}</td>
                                        <td class="text-right">减:{{Order.Discount}}</td>
                                        <td class="text-right">{{Order.PayMoney}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--操作信息-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>操作信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">操作备注：</p></td>
                                        <td colspan="3">

                                                <textarea name="note" placeholder="请输入操作备注" ng-model="Note" rows="3" class="form-control"></textarea>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td class="text-right col-sm-2"><p class="margin">当前可执行操作：</p></td>
                                        <td colspan="3">
                                            <div class="input-group">
                                                @*<button class="btn btn-primary margin"  type="button"  ng-show="Order.PayState==@((int)OrderPayStatus.未支付)&&Order.OrderState==@((int)OrderStatus.待确认)" ng-click="payOrder()">
                                                    付款
                                                </button>*@
                                                <button class="btn btn-primary margin" type="button" ng-show="Order.PayState==@((int)OrderPayStatus.已支付)&&Order.OrderState==@((int)OrderStatus.待确认)" ng-click="confirmOrder()">
                                                    确认
                                                </button>
                                                <button class="btn btn-primary margin" type="button" ng-show="Order.SendStatus==@((int)OrderSendStatus.未发货)&&Order.OrderState==@((int)OrderStatus.已确认)" ng-click="cancelConfirm()">
                                                    取消确认
                                                </button>
                                                <button class="btn btn-primary margin" type="button" ng-show="Order.SendStatus!=@((int)OrderSendStatus.已发货)&&Order.OrderState==@((int)OrderStatus.已确认)" ng-click="goSend()">
                                                    去发货
                                                </button>
                                                @*<button class="btn btn-primary margin" type="button" >
                                                    作废
                                                </button>*@
                                            </div>
                                        </td>

                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <!--操作记录-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0" style="margin-bottom: 0px;">
                                <legend>操作信息</legend>
                            </fieldset>
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td class="text-center">操作者</td>
                                        <td class="text-center">操作时间</td>
                                        <td class="text-center">订单状态</td>
                                        <td class="text-center">付款状态</td>
                                        <td class="text-center">发货状态</td>
                                        <td class="text-center">描述</td>
                                        <td class="text-center">备注</td>
                                    </tr>
                                    <tr ng-repeat="item in OrderRecord">
                                        <td class="text-center">{{item.OpUserName}}</td>
                                        <td class="text-center">{{item.AddTime}}</td>
                                        <td class="text-center">{{item.OrderStatusDes}}</td>
                                        <td class="text-center">{{item.PayStatusDes}}</td>
                                        <td class="text-center">{{item.SendStatusDes}}</td>
                                        <td class="text-center">{{item.OperationNote}}</td>
                                        <td class="text-center">{{item.Remark}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="text-right">
                        <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                        @*<button type="button" class="btn btn-info" ng-click="saveNormalProduct()">保 存</button>*@
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    App.controller('OrderInfoController', ["$scope", "$state", "$http", "$stateParams", "Notify", 'ngTableParams', 'ngTableDataService', 'ngDialog', '$filter', '$rootScope',
        function ($scope, $state, $http, $stateParams, Notify, ngTableParams, ngTableDataService, ngDialog, $filter, $rootScope) {
            'use strict';
            $scope.submitted = false;
            $scope.isLoading = true;
            $scope.IsCheckedPic = false;
            $scope.croppedImageList = [];
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };




            //数据初始化
            $http.post("/Order/GetOrderModel", { id: $stateParams.id }).then(function (response) {
                $scope.Order = response.data.data;
                if (!$scope.Order) {
                    Notify.alert("该订单不存在", { status: 'warning' });
                    $state.go('admin.orderInfoManage');
                    $scope.Order = {};
                }

                $scope.isLoading = false;
            });
            $http.post("/Order/GetOrderDetail", { orderId: $stateParams.id }).then(function (response) {
                $scope.OrderDetail = response.data.data;
            });
            $http.post("/Order/GetOrderRecord", { orderId: $stateParams.id }).then(function (response) {
                $scope.OrderRecord = response.data.data;
            });


            //返回列表
            $scope.cancel = function () {
                if($scope.Order.OrderType==1)
                {
                    $state.go("app.pointOrder");
                }
                else
                {
                    $state.go("app.orderInfoManage", $stateParams);
                }
            }
            //付款
            $scope.payOrder = function () {
                $scope.isLoading = true;
                $http.post("/Order/PayOrder", { orderno: $scope.Order.OrderNo,note:$scope.Note}).then(function (returnData) {

                    if (returnData.data.isSuccess) {
                        Notify.alert('操作成功!', { status: 'success' });
                        $scope.Order.PayState=@((int)OrderPayStatus.已支付);
                        $http.post("/Order/GetOrderRecord", { orderId: $stateParams.id }).then(function (response) {
                            $scope.OrderRecord = response.data.data;
                            $scope.isLoading = false;
                        });
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                        $scope.isLoading = false;
                    }
                });

            }

            //确认
            $scope.confirmOrder = function () {
                $scope.isLoading = true;
                $http.post("/Order/ConfirmOrder", { id: $stateParams.id ,note:$scope.Note}).then(function (returnData) {

                    if (returnData.data.isSuccess) {
                        Notify.alert('操作成功!', { status: 'success' });
                        $scope.Order.OrderState = @((int)OrderStatus.已确认);
                        $http.post("/Order/GetOrderRecord", { orderId: $stateParams.id }).then(function (response) {
                            $scope.OrderRecord = response.data.data;
                            $scope.isLoading = false;
                        });
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                        $scope.isLoading = false;
                    }
                });

            }

            //取消确认
            $scope.cancelConfirm = function () {
                $scope.isLoading = true;
                $http.post("/Order/CancelConfirmOrder", { id: $stateParams.id ,note:$scope.Note}).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        Notify.alert('操作成功!', { status: 'success' });
                        $scope.Order.OrderState = @((int)OrderStatus.待确认);
                        $http.post("/Order/GetOrderRecord", { orderId: $stateParams.id }).then(function (response) {
                            $scope.OrderRecord = response.data.data;
                            $scope.isLoading = false;
                        });
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                        $scope.isLoading = false;
                    }
                });

            }
            //去发货
            $scope.goSend=function()
            {
                $state.go('app.sendOrderInfo',{id:$stateParams.id });
            }

        }]);
</script>
